//
//  SXTTabBarViewController.m
//  SXT
//
//  Created by gaochar on 2017/3/14.
//  Copyright © 2017年 so. All rights reserved.
//

#import "SXTTabBarViewController.h"
#import "SXTNavigationViewController.h"

@interface SXTTabBarViewController ()


/**
 *  用来存储从plist文件中获取的数据
 */
@property (nonatomic, strong) NSArray *tabBarMessageArray;

@end

@implementation SXTTabBarViewController

- (NSArray *)tabBarMessageArray {
    
    if (!_tabBarMessageArray) {
        _tabBarMessageArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SXTTabBarViewController" ofType:@"plist"]];
    }
    return _tabBarMessageArray;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 通过appearance同意设置所有UITabBarItem的文字属性
    // 方法或者属性后面带有UI_APPEARANCE_SELECTOR的，都可以通过appearance对象来统一设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:10.0f], NSForegroundColorAttributeName : [UIColor grayColor]} forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:10.0f], NSForegroundColorAttributeName : [UIColor colorWithRed:57.0/255.0 green:167.0/255.0 blue:241.0/255.0 alpha:1]} forState:UIControlStateSelected];
    
    // 添加子控制器
    for (NSDictionary *dic in self.tabBarMessageArray) {
        Class vcClass = NSClassFromString(dic[@"tabBarController"]);
        UIViewController *vc = [[vcClass alloc] init];
        vc.tabBarItem.image = [UIImage imageNamed:dic[@"tabBarImage"]];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:dic[@"tabBarSelectImage"]];
        vc.title = dic[@"tabBarTitle"];
        SXTNavigationViewController *nav = [[SXTNavigationViewController alloc] initWithRootViewController:vc];
        [self addChildViewController:nav];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
